package com.jia.leetcode2.array;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: designPattern
 * @description:
 * @author: STU756
 * @create: 2021-03-25 13:42
 */
public class TwoSumIII {
    private Map<Integer, Integer> map = new HashMap<>();
    public void add(int input) {
        map.put(input, map.getOrDefault(input, 0) + 1);
    }
    public boolean find(int val) {
        for(Map.Entry<Integer, Integer> entry : map.entrySet()) {
            int num = entry.getKey();
            int target = val - num;
            if(target == num) {
                if(entry.getValue() > 1) { return true; }
            }else if(map.containsKey(target)){
                return true;
            }
        }
        return false;
    }
}
